<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ include file="/common/backcommon.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Breaking Fast</title>
		<script type="text/javascript">
			$(function() {
				$.ajax({
					url: "${base}/backUserCtl/selectCountry",
					type: "post",
					success: function(result){
						var country = $("#countryid");
						for(var i = 0; i < result.length; i++) {
						var selected = "${user.countryid}" == result[i].countryid ? "selected" : "";
							country.append("<option value='" + result[i].countryid + "' " + selected  +" >" + result[i].zhname + "</option>");
						}
					}
				});
				
				//验证信息
				$.formValidator.initConfig({
					formID: "addForm",
					debug:false,
					onError: function(msg, obj, errorlist){
					}
				});
				$("#username").formValidator({onShow:"请输入用户名", onCorrect:"恭喜你,你输对了"}).inputValidator({min:2, max:25, onError:"用户名为2-25个字符"}).regexValidator({regExp: "Illegal", dataType:"enum", onError:"用户名中包含非法字符"});
				$("#email").formValidator({onShow:"请输入email", onCorrect:"恭喜你,你输对了"}).regexValidator({regExp: "email", dataType:"enum", onError:"你输入的邮箱格式不正确"})
			    .ajaxValidator({
					dataType : "json",
					async : true,
					url : "${base}/backUserCtl/checkAccountName",
					success : function(data){
						if("" != $("#userid").val()) {
							return true;
						} else if("0" == data) {
			            	return true;
		            	} else {
							return "该登陆名已被使用，请更换用户名";
						}
					},
					buttons: $("#button"),
					error: function(jqXHR, textStatus, errorThrown) {
						alert("服务器没有返回数据，可能服务器忙，请重试" + errorThrown);
					},
					onError : "该登陆名已被使用，请更换用户名",
					onWait : "正在对用户名进行合法性校验，请稍候..."
				});
				$("#password").formValidator({onShow:"请输入密码",onFocus:"至少6个长度",onCorrect:"密码合法"}).inputValidator({min:6, max:25, empty:{leftEmpty:false,rightEmpty:false,emptyError:"密码两边不能有空符号"},onError:"密码为6-25个字符,请确认"}).regexValidator({regExp: "Illegal", dataType:"enum", onError:"密码中包含非法字符"});
				$("#repassword").formValidator({onShow:"输再次输入密码",onFocus:"至少6个长度",onCorrect:"密码一致"}).inputValidator({min:6, max:25, empty:{leftEmpty:false,rightEmpty:false,emptyError:"重复密码两边不能有空符号"},onError:"重复密码为6-25个字符,请确认"}).compareValidator({desID:"password",operateor:"=",onError:"两次密码不一致,请确认"});
				$("#sex").formValidator({onShow:"请选择用户性别", onCorrect:"恭喜你,你输对了"}).inputValidator({min:1, onError:"请选择性别"});
				$("#phone").formValidator({onShow:"请输入电话/手机号码", onCorrect:"恭喜你,你输对了"}).regexValidator({regExp: "telphone", dataType:"enum", onError:"你输入的电话/手机号码格式不正确"});
				$("#address").formValidator({onShow:"请输入地址", onCorrect:"恭喜你,你输对了"}).inputValidator({max:250, onError:"地址为1-250个字"}).regexValidator({regExp: "Illegal", dataType:"enum", onError:"地址中包含非法字符"});
				function init() {
					if("" != $("#userid").val()) {
						$("#email").attr("readonly", "readonly");
					}
				}
				init();
			});
		</script>
	</head>
	<body>
		<div class="cms_right">
		  	<div class="cms_title">
		    	<span>用户管理：${user.userid == null ? "新增" : "修改"} </span>
		    </div>
		    <div class="cms_search">
		    	<form:form id="addForm" commandName="user" action="${base}/backUserCtl/add" method="post">
					<table width="1000" border="0" class="search_bd">
			          	<tr>
				            <td class="yh_name">email：</td>
				            <td class="yh_bd"><input type="text" id="email" name="email" class="cms_text02" maxlength="100" value="${user.email}"/></td>
				            <td class="tishi"><div id="emailTip" ></div></td>
				            <td class="yh_name">用户名：</td>
				            <td class="yh_bd"><input type="text" id="username"name="username" class="cms_text02" maxlength="25" value="${user.username}"/></td>
				            <td class="tishi"><div id="usernameTip" ></div></td>
			          	</tr>
			          	<tr>
				            <td class="yh_name">密码：</td>
				            <td class="yh_bd"><input type="password" id="password" name="password" class="cms_text02" maxlength="25" /></td>
				            <td class="tishi"><div id="passwordTip"></div></td>
				            <td class="yh_name">重复密码：</td>
				            <td class="yh_bd"><input type="password" id="repassword" class="cms_text02" maxlength="25" /></td>
				            <td class="tishi"><div id="repasswordTip"></div></td>
			          	</tr>
			          	<tr>
				            <td class="yh_name">性别：</td>
				            <td class="yh_bd">
					            <select id="sex" name="sex" class="cms_text02" >
					            	<option value="" selected="selected">=请选择=</option>
					            	<option value="1" ${1 == user.sex ? "selected" : ""}>男</option>
					            	<option value="0" ${0 == user.sex ? "selected" : ""}>女</option>
					            </select>
				            </td>
				            <td class="tishi"><div id="sexTip" ></div></td>
				            <td class="yh_name">国家：</td>
				            <td class="yh_bd">
					            <select id="countryid" name="countryid" class="cms_text02" >
					            	<option value="" selected="selected">=请选择=</option>
					            </select>
							</td>
				            <td class="tishi"><div id="countryidTip" ></div></td>
			          	</tr>
			          	<tr>
				            <td class="tishi"><input type="hidden" name="type" value="1" /></td>
				            <td class="yh_name">手机号码：</td>
				            <td class="yh_bd"><input type="text" id="phone" name="phone" class="cms_text02" maxlength="11" value="${user.phone}"/></td>
				            <td class="tishi"><div id="phoneTip"></div></td>
				            <td class="yh_name">用户类型：</td>
				            <td class="yh_bd">
				            	<select class="cms_text02" id="type" name="type" >
					            	<option value="" selected="selected">=请选择=</option>
				            		<option value="0" ${0 == user.type ? "selected" : ""}>前台用户</option>
				            		<option value="1" ${1 == user.type ? "selected" : ""}>后台用户</option>
				            	</select>
			            	</td>
			          	</tr>
			          	<tr>
				            <td class="yh_name">地址：</td>
				            <td class="yh_bd" colspan="4">
				            	<input type="text" id="address" name="address" class="cms_text02" style="width:650px" value="${user.address}" />
			            	</td>
				            <td class="tishi"><div id="addressTip"></div></td>
			          	</tr>
			          	<tr>
				            <td>&nbsp;</td>
				            <td align="right"><input type="reset" class="search_btn" value="重置" /></td>
				            <td align="center"><input type="button" class="search_btn" onclick="location.href='${base}/background/user/userlist.jsp'" value="返回" /></td>
				            <td><input type="submit" class="search_btn" value="确定" /></td>
				            <td>&nbsp;</td>
				            <td><input type="hidden" id="userid" name="userid" value="${user.userid}" /></td>
						</tr>
					</table>
				</form:form>
			</div>
		</div>
	</body>
</html>
	